//
// Created by Zhang on 2022/5/20.
//
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

//extra q1
class Point {
    int x, y;
public:
    Point() {
        x = 0;
        y = 0;
    }

    Point(int a, int b) : x(a), y(b) {};

    friend std::istream &operator>>(std::istream &input, Point &D) {
        std::cout << "x:";
        input >> D.x;
        std::cout << "y:";
        input >> D.y;

        return input;
    }

    friend std::ostream &operator<<(std::ostream &output,
                                    const Point &D) {
        output << " x:" << D.x << " Y:" << D.y;
        return output;
    }

};

//extra q3
class CStudent {
    std::string name;
    int a, b, c, avg;
public:
    long id;

    CStudent(std::string name, long id, int a, int b, int c) : name(name), id(id), a(a), b(b), c(c) {
        avg = (a + b + c) / 3;
    }

    void print() {
        std::cout << name << " " << id << " " << a << " " << b << " " << c << " " << avg << std::endl;

    }

    bool Validate() const {
        if (avg == (a + b + c) / 3)return true; else return false;
    }

    friend bool bigger(const CStudent &a, const CStudent &b);
};

bool bigger(const CStudent &a, const CStudent &b) {
    return a.avg > b.avg;
}

class CStuFile {
    std::vector<CStudent> S;

public:
    void AddT0(const CStudent &b) {
        S.push_back(b);
    }

    void List() {
        for (auto i:S) {
            i.print();
        }
    }

    void Sort() {
        std::sort(S.begin(), S.end(), bigger);
    };

    CStudent seek(long id) {
        for (auto i:S) {
            if (i.id == id) {
                return i;
            }
        };
        return *((CStudent *) nullptr);
    };

    void Delete(long id) {
        for (auto it = S.begin(); it != S.end(); it++) {
            if (it->id == id) {
                S.erase(it);
            }
        }
    }
};


int main() {
    //extra q1
    Point a(21, 25);
//    std::cin>>a;
    std::cout << a << std::endl;
    std::ofstream file6("point.txt", std::ios::trunc);
    file6 << a;
    file6.close();

    //extra q2
    float sqrt[21];
    for (int i = 1; i <= 20; i++)sqrt[i] = std::sqrt(i);
    std::ofstream file7("data7.deb", std::ios::trunc | std::ios::binary);
    file7.write((char *) &sqrt, sizeof(float) * 21);
    file7.close();
    std::ifstream file8("data7.deb", std::ios::binary);
    float sqrt2[21];
    file8.read((char *) &sqrt2, sizeof(float) * 21);
    file8.close();

    for (int i = 1; i <= 20; i++)std::cout << sqrt2[i] << " ";
    std::cout << std::endl;

    //extra q3
    CStudent a1("abc", 1000, 1, 2, 3), a2("bcd", 1001, 1, 3, 5), a3("bbb", 1002, 21, 34, 56);
    CStuFile B;
    B.AddT0(a1);
    B.AddT0(a2);
    B.AddT0(a3);
    B.List();
    B.Sort();
    std::cout << std::endl;
    B.List();
    std::cout << std::endl;
    B.seek(1000).print();
    B.Delete(1001);
    std::cout << std::endl;
    B.List();


    return 0;

}
